/*
 ============================================================================
 Name		: Flashbox4AppUi.h
 Author	  : ceze
 Copyright   : FlashBox for ver.Zhongyou(???)
 Description : Declares UI class for application.
 ============================================================================
 */

#ifndef __FLASHBOX4APPUI_h__
#define __FLASHBOX4APPUI_h__

// INCLUDES
#include <aknviewappui.h>
#include <Etel3rdParty.h>//Link against: etel3rdparty.lib 
#include <S32FILE.H>

#include "ConstDefined.hrh"
#include "webclientengine.h"

#ifdef _CHARGE_ON_UI_ 
#include "etcharge.h"
#endif 

// FORWARD DECLARATIONS

// CLASS DECLARATION
//class CWebClientEngine;
//class MWebClientObserver;


//Http 请求数据结构
class CFbHttpQueryData : public CBase
{
public:
	//请求类型
	enum TQueryType
	{
		ETypeGet = 0, 
		ETypePost = 1
	};

	static CFbHttpQueryData
			* NewL (TQueryType aType, TInt aSesion, MWebClientObserver* aObserver,
					const TDesC8& aUri, const TDesC8& aData, 
					const TDesC8& aCookie, TBool aReplaceHost, TBool aBufferAll);

	~CFbHttpQueryData ();

private:
	void ConstructL (const TDesC8& aUri, const TDesC8& aData,
			const TDesC8& aCookie );
	//
	CFbHttpQueryData (TQueryType aType, TInt aSession, 
			MWebClientObserver* aObserver, TBool aReplaceHost,TBool aBufferAll);

public:
	TQueryType iQueryType;
	HBufC8* iQueryUri;
	HBufC8* iQueryData;
	HBufC8* iCookie;
	MWebClientObserver* iObserver;//回调接口
	TInt iSessionId;//请求方指定的sessionid
	TBool iReplaceHost;
	TBool iBufferAll;
};
/**
 * 设置项数据结构
 */
class CFbSettingItem : public CBase
{
public:
	CFbSettingItem ()
	{
	}
	
	~CFbSettingItem ()
	{
	}
public:
	TBool m_isOn; //状态
	TInt32 m_fileId; //File id
	TFileName m_FileName; //文件名称
	TFileName m_FilePath; //文件路径
	TFileName m_IconPath; //对应图标路径
};

/**
 * CFlashbox4AppUi application UI class.
 * Interacts with the user through the UI and request message processing
 * from the handler class
 */
class CFlashbox4AppUi : public CAknViewAppUi, CActive
#ifdef _CHARGE_ON_UI_
		//,MWebClientObserver
		,MChargeObserver
#endif
{
public:
	// Constructors and destructor

	/**
	 * ConstructL.
	 * 2nd phase constructor.
	 */
	void ConstructL ();

	/**
	 * CFlashbox4AppUi.
	 * C++ default constructor. This needs to be public due to
	 * the way the framework constructs the AppUi
	 */
	CFlashbox4AppUi ();

	/**
	 * ~CFlashbox4AppUi.
	 * Virtual Destructor.
	 */
	virtual ~CFlashbox4AppUi ();

	/**
	 * 激活视图窗口
	 * aViewId : 窗口ViewId
	 */
	void ActiveViewL (TInt aViewId, TInt aTabIndex = 0 );

	/**
	 * 初始化HttpEngine
	 */
	void InitializeHttpEngineL (MWebClientObserver * pObserver );

	/*
	 * Post http连接
	 */
	TBool IssueHttpPostL (MWebClientObserver *pObserver, const TDesC8& aUri, 
			const TDesC8& aBodyData, const TDesC8& aCookie = KNullDesC8, 
			TInt aSessionId = -1, TBool aReplaceHost =EFalse, TInt aLevel = 0 , 
			TBool aBufferAll = ETrue);

	/**
	 * get http连接
	 */
	TBool IssueHttpGetL (MWebClientObserver *pObserver, const TDesC8& aUri, 
			TInt aSessionId =-1, TBool aReplaceHost = EFalse, 
			TInt aLevel = 0 , 	TBool aBufferAll = ETrue);

	/**
	 * 取消连接
	 */
	void CancelHttpQueryL (TInt aSession = -1, TBool isDeleteObserver = EFalse );

	void WriteDataToStreamL (RFileWriteStream &out, CFbSettingItem *pData );
	void ReadDataFromStreamL (RFileReadStream &in, CFbSettingItem *pData );

	
private:
	//读取设置
	void LoadSettingConfigL ();
	
	/**
	 * aUri 请求链接
	 * Type :请求类型 Post或GET
	 * aSessionId : 请求session
	 * aBody: post内容
	 * aCookie: 请求cookie
	 * aObserver: 是否替换host(wap网关0))
	 * aLevel: 请求优先级 
	 */
	void HttpQueryL (const TDesC8 &aUri, TInt aType, TInt aSessionId, 
			const TDesC8& aBody, const TDesC8& aCookie, 
			MWebClientObserver* aObserver, TBool aReplaceHost, TInt aLevel, TBool aBufferAll);

	// Functions from base classes
	//from CActive
	void RunL ();
	void DoCancel ();

	/**
	 * From CEikAppUi, HandleCommandL.
	 * Takes care of command handling.
	 * @param aCommand Command to be handled.
	 */
	void HandleCommandL (TInt aCommand );

	/**
	 * From CEikAppUi, handles key events.
	 * @param aKeyEvent Event to handled.
	 * @param aType Type of the key event. 
	 * @return Response code (EKeyWasConsumed, EKeyWasNotConsumed). 
	 */
	virtual TKeyResponse
			HandleKeyEventL (const TKeyEvent& aKeyEvent, TEventCode aType );

	/**
	 *  From CCoeAppUi, HelpContextL.
	 *  Provides help context for the application.
	 *  size is changed.
	 */
	CArrayFix<TCoeHelpContext>* HelpContextL () const;

private:
	//TInt	iState;
	RTimer iTimer; // Provides async timing service
	CArrayPtrFlat<CFbHttpQueryData> *m_pHttpQueryBuffer;//连接请求缓存

	//Http连接引擎
	CWebClientEngine *m_pHttpEngine;

#ifdef _CHARGE_ON_UI_	
	void IsCharged (TBool aCharged, TInt aSum, TInt aCurrentNum );
	//CETCharge * m_pETCharge;

	////////////////////MWebClientObserver接口函数//////////////
	/**
	 * WebClientEvent()
	 * Called when event occurs in CWebClientEngine.
	 * @param aEventDescription: A event in textual format, e.g.
	 *                           "Transaction Successful"
	 */
	//void WebClientEvent (const TInt aEvent, TInt aSessionId,/*const TDesC& aEventDescription,*/
	//		TInt aCode = 0 );

	/**
	 * WebClientHeaderReceived()
	 * Called when HTTP header is received.
	 * @param aHeaderData: Header field name and value
	 */
	//void WebClientHeaderReceived (const TDesC8& aHeaderFiled, const TDesC8& aHeaderVal, TInt aSessionId );

	/**
	 * WebClientBodyReceivedComplete()
	 * Called when a part of the HTTP body is received.
	 * @param aBodyData:  Part of the body data received. (e.g. part of
	 *                    the received HTML page)
	 */
	//void WebClientBodyReceivedComplete (const TDesC8& aBodyData, TInt aSessionId );
	
	//结束程序提示
	void IsTerminateApp ();
	
public:	
	//启动短信计费路程
	void StartSmsCharge(const TDesC8 &aCmdXml);
#endif
	
public:
	//手机系统信息imei, model ...
	CTelephony::TPhoneIdV1 m_mobileInfo;

	//屏保设置信息
	CFbSettingItem *m_pSettingPingbao;
	//来电设置信息
	CFbSettingItem *m_pSettingLaidian;
	RFs m_fs;

private:
	
#ifdef _CHARGE_ON_UI_
	enum TInitState
	{
		EStateOnInitHttp = 0x100, //初始化Http
		EStateOnQueryXml,//获取sms指令
		EStateOnCharge,
		EStateOnGePhoneNumber//获取手机号码（向服务器发短信）
	//发送短信
	};

	CETCharge * m_pETCharge;
	HBufC8 *m_pSmsContentString;
	TInt 	m_chargeState;
#endif
	

};

#endif // __FLASHBOX4APPUI_h__
// End of File
